// Copyright 2012, Jun Chen .All rights reserved.
//
// Use of this source code is governed by a BSD-Style license that can be
// found in the License fule.
//
// Author: cpp.cheen at gmail dot com.


#ifndef EVT_THREADPOOL_H
#define EVT_THREADPOOL_H

#include    "pch_files.h"
#include    <boost/thread.hpp>
#include    <boost/ptr_container/ptr_vector.hpp>

class evt_dispather;
class evt_thread;

class evt_threadpool
{
    typedef boost::ptr_vector<evt_dispather>    dsp_ptr_vec;
    typedef boost::ptr_vector<evt_thread>       evt_thread_ptr_vec;
    public:
        /** Default constructor */
        evt_threadpool(evt_dispather*   dispather);
        /** Default destructor */
        virtual ~evt_threadpool();

        x_int32     add_threads(x_uint32 number);

        void        run();
        void        exit();

        evt_dispather*  get_dispather();
    protected:
    private:
        evt_thread_ptr_vec     m_threads;
        boost::mutex            m_disp_vec_mutex;
        evt_dispather*          m_main_dispather;
        dsp_ptr_vec             m_dispather_ptrs;
        x_uint32                m_dsp_index;
};

#endif // EVT_THREADPOOL_H
